package com.interview03;

public class Movie {
	private String pic;
	private boolean flag = true;
	
 
	public synchronized void play(String pic){
		if(!flag){ // 如果flag 是false，停下不生产
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		// 开始生产
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("我播放了电影=====>"+pic);
		this.pic = pic;
		
		//生产结束 ，叫醒消费者
		this.notify();
		//改变信号灯
		this.flag = false;
	}
	
	
	public synchronized void watch(){
		if(flag){//如果flag是true ，停止观看
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
		//开始观看
		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("我看了 --》"+pic);
		//看完之后.叫醒生产者，开始生产
		this.notifyAll();
		//改变信号灯
		this.flag = true;
	}
}